using Digitalmes.Application.Scada.Models;
using Digitalmes.Application.Scada.Services;

namespace Digitalmes.Application.Scada.Commands;

internal sealed class ScanBatchCommandHandler(IServiceScopeFactory serviceScopeFactory) : IRequestHandler<ScanBatchCommand, ScadaResult>
{
    public async Task<ScadaResult> Handle(ScanBatchCommand request, CancellationToken cancellationToken)
    {
        using var scope = serviceScopeFactory.CreateScope();
        var service = scope.ServiceProvider.GetRequiredService<IScanBatchService>();
        ScanBatchInput input = new(request.LineCode, request.WsCode, request.Barcode, request.Qty);
        return await service.ScanAsync(input, cancellationToken).ConfigureAwait(false);
    }
}
